
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>REST接口（REST API） · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="authentication_using_oauth.html" />
    
    
    <link rel="prev" href="local_files.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    Introduction
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../meet_qt_5/">
            
                <a href="../meet_qt_5/">
            
                    
                    Qt5概述
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="../meet_qt_5/preface.html">
            
                <a href="../meet_qt_5/preface.html">
            
                    
                    序
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="../meet_qt_5/qt5_introduction.html">
            
                <a href="../meet_qt_5/qt5_introduction.html">
            
                    
                    Qt5介绍
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3" data-path="../meet_qt_5/qt_building_blocks.html">
            
                <a href="../meet_qt_5/qt_building_blocks.html">
            
                    
                    Qt构建模块（Qt Building Blocks）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.4" data-path="../meet_qt_5/qt_project.html">
            
                <a href="../meet_qt_5/qt_project.html">
            
                    
                    Qt项目（Qt Project）
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../get_start/">
            
                <a href="../get_start/">
            
                    
                    开始学习（Get Start）
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../get_start/qt5installing_qt_5_sdk.html">
            
                <a href="../get_start/qt5installing_qt_5_sdk.html">
            
                    
                    安装Qt5软件工具包（Installing Qt 5 SDK）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="../get_start/hello_world.html">
            
                <a href="../get_start/hello_world.html">
            
                    
                    你好世界（Hello World）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="../get_start/application_types.html">
            
                <a href="../get_start/application_types.html">
            
                    
                    应用程序类型（Application Types）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.4" data-path="../get_start/summary.html">
            
                <a href="../get_start/summary.html">
            
                    
                    总结（ Summary）
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../qt_creator_ide/">
            
                <a href="../qt_creator_ide/">
            
                    
                    Qt Creator集成开发环境（Qt Creator IDE）
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="../qt_creator_ide/the_user_interface.html">
            
                <a href="../qt_creator_ide/the_user_interface.html">
            
                    
                    用户界面（The User Interface）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="../qt_creator_ide/qtregistering_your_qt_kit.html">
            
                <a href="../qt_creator_ide/qtregistering_your_qt_kit.html">
            
                    
                    注册你的Qt工具箱（Registering your Qt Kit）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3" data-path="../qt_creator_ide/managing_projects.html">
            
                <a href="../qt_creator_ide/managing_projects.html">
            
                    
                    项目管理（Managing Projects）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.4" data-path="../qt_creator_ide/using_the_editor.html">
            
                <a href="../qt_creator_ide/using_the_editor.html">
            
                    
                    使用编辑器（Using the Editor）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.5" data-path="../qt_creator_ide/locator.html">
            
                <a href="../qt_creator_ide/locator.html">
            
                    
                    定位器（Locator）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.6" data-path="../qt_creator_ide/debugging.html">
            
                <a href="../qt_creator_ide/debugging.html">
            
                    
                    调试（Debugging）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.7" data-path="../qt_creator_ide/shortcuts.html">
            
                <a href="../qt_creator_ide/shortcuts.html">
            
                    
                    快捷键（Shortcuts）
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="../quick_starter/">
            
                <a href="../quick_starter/">
            
                    
                    QML快速入门（Quick Starter）
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="../quick_starter/qmlqml_syntax.html">
            
                <a href="../quick_starter/qmlqml_syntax.html">
            
                    
                    QML语法（QML Syntax）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="../quick_starter/basic_elements.html">
            
                <a href="../quick_starter/basic_elements.html">
            
                    
                    基本元素（Basic Elements）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.3" data-path="../quick_starter/compontents.html">
            
                <a href="../quick_starter/compontents.html">
            
                    
                    组件（Compontents）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.4" data-path="../quick_starter/simple_transformations.html">
            
                <a href="../quick_starter/simple_transformations.html">
            
                    
                    简单的转换（Simple Transformations）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.5" data-path="../quick_starter/positioning_element.html">
            
                <a href="../quick_starter/positioning_element.html">
            
                    
                    定位元素（Positioning Element）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.6" data-path="../quick_starter/layout_items.html">
            
                <a href="../quick_starter/layout_items.html">
            
                    
                    布局元素（Layout Items）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.7" data-path="../quick_starter/input_element.html">
            
                <a href="../quick_starter/input_element.html">
            
                    
                    输入元素（Input Element）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.8" data-path="../quick_starter/advanced_techniques.html">
            
                <a href="../quick_starter/advanced_techniques.html">
            
                    
                     高级用法（Advanced Techniques）
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="../fluid_elements/">
            
                <a href="../fluid_elements/">
            
                    
                    动态元素（Fluid Elements）
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1" data-path="../fluid_elements/animations.html">
            
                <a href="../fluid_elements/animations.html">
            
                    
                    动画（Animations）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2" data-path="../fluid_elements/states_and_transitions.html">
            
                <a href="../fluid_elements/states_and_transitions.html">
            
                    
                    状态与过渡（States and Transitions）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.3" data-path="../fluid_elements/advanced_techniques.html">
            
                <a href="../fluid_elements/advanced_techniques.html">
            
                    
                    高级用法（Advanced Techniques）
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="../model-view-delegate/">
            
                <a href="../model-view-delegate/">
            
                    
                    模型-视图-代理（Model-View-Delegate）
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.1" data-path="../model-view-delegate/concept.html">
            
                <a href="../model-view-delegate/concept.html">
            
                    
                    概念（Concept）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.2" data-path="../model-view-delegate/basic_model.html">
            
                <a href="../model-view-delegate/basic_model.html">
            
                    
                    基础模型（Basic Model）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.3" data-path="../model-view-delegate/dynamic_views.html">
            
                <a href="../model-view-delegate/dynamic_views.html">
            
                    
                    动态视图（Dynamic Views）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.4" data-path="../model-view-delegate/delegate.html">
            
                <a href="../model-view-delegate/delegate.html">
            
                    
                    代理（Delegate）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.5" data-path="../model-view-delegate/advanced_techniques.html">
            
                <a href="../model-view-delegate/advanced_techniques.html">
            
                    
                    高级用法（Advanced Techniques）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.6" data-path="../model-view-delegate/summary.html">
            
                <a href="../model-view-delegate/summary.html">
            
                    
                    总结（Summary）
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="../canvas_element/">
            
                <a href="../canvas_element/">
            
                    
                    画布元素（Canvas Element）
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.8.1" data-path="../canvas_element/convenient_api.html">
            
                <a href="../canvas_element/convenient_api.html">
            
                    
                    便捷的接口（Convenient API）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.2" data-path="../canvas_element/gradients.html">
            
                <a href="../canvas_element/gradients.html">
            
                    
                    渐变（Gradients）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.3" data-path="../canvas_element/shadows.html">
            
                <a href="../canvas_element/shadows.html">
            
                    
                    阴影（Shadows）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.4" data-path="../canvas_element/images.html">
            
                <a href="../canvas_element/images.html">
            
                    
                    图片（Images）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.5" data-path="../canvas_element/transformation.html">
            
                <a href="../canvas_element/transformation.html">
            
                    
                    转换（Transformation）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.6" data-path="../canvas_element/composition_mode.html">
            
                <a href="../canvas_element/composition_mode.html">
            
                    
                    组合模式（Composition Mode）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.7" data-path="../canvas_element/pixels_buffer.html">
            
                <a href="../canvas_element/pixels_buffer.html">
            
                    
                    像素缓冲（Pixels Buffer）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.8" data-path="../canvas_element/canvas_paint.html">
            
                <a href="../canvas_element/canvas_paint.html">
            
                    
                    画布绘制（Canvas Paint）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.9" data-path="../canvas_element/html5porting_from_html5_canvas.html">
            
                <a href="../canvas_element/html5porting_from_html5_canvas.html">
            
                    
                    HTML5画布移植（Porting from HTML5 Canvas）
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="../particle_simulations/">
            
                <a href="../particle_simulations/">
            
                    
                    粒子模拟（Particle Simulations）
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.9.1" data-path="../particle_simulations/concept.html">
            
                <a href="../particle_simulations/concept.html">
            
                    
                    概念（Concept）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.2" data-path="../particle_simulations/simple_simulation.html">
            
                <a href="../particle_simulations/simple_simulation.html">
            
                    
                    简单的模拟（Simple Simulation）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.3" data-path="../particle_simulations/particle_parameters.html">
            
                <a href="../particle_simulations/particle_parameters.html">
            
                    
                    粒子参数（Particle Parameters）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.4" data-path="../particle_simulations/directed_particle.html">
            
                <a href="../particle_simulations/directed_particle.html">
            
                    
                    粒子方向（Directed Particle）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.5" data-path="../particle_simulations/particle_painter.html">
            
                <a href="../particle_simulations/particle_painter.html">
            
                    
                    粒子画笔（Particle Painter）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.6" data-path="../particle_simulations/affecting_particles.html">
            
                <a href="../particle_simulations/affecting_particles.html">
            
                    
                    粒子控制（Affecting Particles）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.7" data-path="../particle_simulations/particle_group.html">
            
                <a href="../particle_simulations/particle_group.html">
            
                    
                    粒子组（Particle Group）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.8" data-path="../particle_simulations/summary.html">
            
                <a href="../particle_simulations/summary.html">
            
                    
                    总结（Summary）
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.10" data-path="../shader_effect/">
            
                <a href="../shader_effect/">
            
                    
                    着色器效果（Shader Effect）
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.10.1" data-path="../shader_effect/openglopengl_shader.html">
            
                <a href="../shader_effect/openglopengl_shader.html">
            
                    
                    OpenGL着色器（OpenGL Shader）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.2" data-path="../shader_effect/shader_elements.html">
            
                <a href="../shader_effect/shader_elements.html">
            
                    
                    着色器元素（Shader Elements）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.3" data-path="../shader_effect/fragement_shader.html">
            
                <a href="../shader_effect/fragement_shader.html">
            
                    
                    片段着色器（Fragement Shader）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.4" data-path="../shader_effect/wave_effect.html">
            
                <a href="../shader_effect/wave_effect.html">
            
                    
                    波浪效果（Wave Effect）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.5" data-path="../shader_effect/vertex_shader.html">
            
                <a href="../shader_effect/vertex_shader.html">
            
                    
                    顶点着色器（Vertex Shader）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.6" data-path="../shader_effect/curtain_effect.html">
            
                <a href="../shader_effect/curtain_effect.html">
            
                    
                    剧幕效果（Curtain Effect）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.7" data-path="../shader_effect/qtqt_graphicseffect_library.html">
            
                <a href="../shader_effect/qtqt_graphicseffect_library.html">
            
                    
                    Qt图像效果库（Qt GraphicsEffect Library）
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.11" data-path="../multimedia/">
            
                <a href="../multimedia/">
            
                    
                    多媒体（Multimedia）
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.11.1" data-path="../multimedia/playing_media.html">
            
                <a href="../multimedia/playing_media.html">
            
                    
                    媒体播放（Playing Media）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.2" data-path="../multimedia/sounds_effects.html">
            
                <a href="../multimedia/sounds_effects.html">
            
                    
                    声音效果（Sounds Effects）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.3" data-path="../multimedia/video_streams.html">
            
                <a href="../multimedia/video_streams.html">
            
                    
                    视频流（Video Streams）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.4" data-path="../multimedia/capturing_images.html">
            
                <a href="../multimedia/capturing_images.html">
            
                    
                    捕捉图像（Capturing Images）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.5" data-path="../multimedia/advanced_techniques.html">
            
                <a href="../multimedia/advanced_techniques.html">
            
                    
                    高级用法（Advanced Techniques）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.6" data-path="../multimedia/summary.html">
            
                <a href="../multimedia/summary.html">
            
                    
                    总结（Summary）
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.12" data-path="./">
            
                <a href="./">
            
                    
                    网络（Networking）
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.12.1" data-path="httpuiserving_ui_via_http.html">
            
                <a href="httpuiserving_ui_via_http.html">
            
                    
                    通过HTTP服务UI（Serving UI via HTTP）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.2" data-path="templating.html">
            
                <a href="templating.html">
            
                    
                    模板（Templating）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.3" data-path="httphttp_requests.html">
            
                <a href="httphttp_requests.html">
            
                    
                    HTTP请求（HTTP Requests）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.4" data-path="local_files.html">
            
                <a href="local_files.html">
            
                    
                    本地文件（Local files）
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.12.5" data-path="restrest_api.html">
            
                <a href="restrest_api.html">
            
                    
                    REST接口（REST API）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.6" data-path="authentication_using_oauth.html">
            
                <a href="authentication_using_oauth.html">
            
                    
                    使用开放授权登陆验证（Authentication using OAuth）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.7" data-path="engine_io.html">
            
                <a href="engine_io.html">
            
                    
                    云服务（Engine IO）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.8" data-path="web_sockets.html">
            
                <a href="web_sockets.html">
            
                    
                    Web Sockets
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.9" data-path="summary.html">
            
                <a href="summary.html">
            
                    
                    总结（Summary）
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.13" data-path="../storage/">
            
                <a href="../storage/">
            
                    
                    存储（Storage）
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.13.1" data-path="../storage/settings.html">
            
                <a href="../storage/settings.html">
            
                    
                    配置（Settings）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.2" data-path="../storage/local_storage_-_sql.html">
            
                <a href="../storage/local_storage_-_sql.html">
            
                    
                    本地存储 - SQL（Local Storage - SQL）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.3" data-path="../storage/other_storage_apis.html">
            
                <a href="../storage/other_storage_apis.html">
            
                    
                    其它存储接口（Other Storage APIs）
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.14" data-path="../dynamic_qml/">
            
                <a href="../dynamic_qml/">
            
                    
                    动态QML（Dynamic QML）
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.14.1" data-path="../dynamic_qml/loading_components_dynamically.html">
            
                <a href="../dynamic_qml/loading_components_dynamically.html">
            
                    
                    动态加载组件（Loading Components Dynamically）
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.14.1.1" data-path="../dynamic_qml/connecting_indirectly.html">
            
                <a href="../dynamic_qml/connecting_indirectly.html">
            
                    
                    间接连接（Connecting Indirectly）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.14.1.2" data-path="../dynamic_qml/binding_indirectly.html">
            
                <a href="../dynamic_qml/binding_indirectly.html">
            
                    
                    间接绑定（Binding Indirectly）
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.14.2" data-path="../dynamic_qml/creating_and_destroying_objects.html">
            
                <a href="../dynamic_qml/creating_and_destroying_objects.html">
            
                    
                    创建与销毁对象（Creating and Destroying Objects）
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.14.2.1" data-path="../dynamic_qml/dynamically_loading_and_instantiating_items.html">
            
                <a href="../dynamic_qml/dynamically_loading_and_instantiating_items.html">
            
                    
                    动态加载和实例化项（Dynamically Loading and Instantiating Items）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.14.2.2" data-path="../dynamic_qml/dynamically_instantiating_items_from_text.html">
            
                <a href="../dynamic_qml/dynamically_instantiating_items_from_text.html">
            
                    
                    从文本中动态实例化项（Dynamically Instantiating Items from Text）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.14.2.3" data-path="../dynamic_qml/managing_dynamically_created_elements.html">
            
                <a href="../dynamic_qml/managing_dynamically_created_elements.html">
            
                    
                    管理动态创建的元素（Managing Dynamically Created Elements）
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.14.3" data-path="../dynamic_qml/tracking_dynamic_objects.html">
            
                <a href="../dynamic_qml/tracking_dynamic_objects.html">
            
                    
                    跟踪动态对象（Tracking Dynamic Objects）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.14.4" data-path="../dynamic_qml/summary.html">
            
                <a href="../dynamic_qml/summary.html">
            
                    
                    总结（Summary）
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.15" data-path="../javascript/">
            
                <a href="../javascript/">
            
                    
                    JavaScript
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.15.1" data-path="../javascript/browserhtml_vs_qtquickqml.html">
            
                <a href="../javascript/browserhtml_vs_qtquickqml.html">
            
                    
                    浏览器/HTML与QtQuick/QML对比（Browser/HTML vs QtQuick/QML）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.2" data-path="../javascript/the_language.html">
            
                <a href="../javascript/the_language.html">
            
                    
                    JavaScript语法（The Language）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.3" data-path="../javascript/js_objects.html">
            
                <a href="../javascript/js_objects.html">
            
                    
                    JS对象（JS Objects）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.4" data-path="../javascript/creating_a_js_console.html">
            
                <a href="../javascript/creating_a_js_console.html">
            
                    
                    创建JS控制台（Creating a JS Console）
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.16" data-path="../qt_and_c++/">
            
                <a href="../qt_and_c++/">
            
                    
                    Qt and C++
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.16.1" data-path="../qt_and_c++/a_boilerplate_application.html">
            
                <a href="../qt_and_c++/a_boilerplate_application.html">
            
                    
                    演示程序（A Boilerplate Application）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.16.2" data-path="../qt_and_c++/the_qobject.html">
            
                <a href="../qt_and_c++/the_qobject.html">
            
                    
                    Qt对象（The QObject）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.16.3" data-path="../qt_and_c++/build_systems.html">
            
                <a href="../qt_and_c++/build_systems.html">
            
                    
                    编译系统（Build Systems）
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.16.3.1" data-path="../qt_and_c++/qmake.html">
            
                <a href="../qt_and_c++/qmake.html">
            
                    
                    QMake
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.16.3.2" data-path="../qt_and_c++/cmake.html">
            
                <a href="../qt_and_c++/cmake.html">
            
                    
                    CMake
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.16.4" data-path="../qt_and_c++/common_qt_classes.html">
            
                <a href="../qt_and_c++/common_qt_classes.html">
            
                    
                    Qt通用类（Common Qt Classes）
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.16.4.1" data-path="../qt_and_c++/qstring.html">
            
                <a href="../qt_and_c++/qstring.html">
            
                    
                    QString
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.16.4.2" data-path="../qt_and_c++/sequential_containers.html">
            
                <a href="../qt_and_c++/sequential_containers.html">
            
                    
                    顺序容器（Sequential Containers）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.16.4.3" data-path="../qt_and_c++/associative_containers.html">
            
                <a href="../qt_and_c++/associative_containers.html">
            
                    
                    组合容器（Associative Containers）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.16.4.4" data-path="../qt_and_c++/file_io.html">
            
                <a href="../qt_and_c++/file_io.html">
            
                    
                    文件IO（File IO）
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.16.5" data-path="../qt_and_c++/models_in_c++.html">
            
                <a href="../qt_and_c++/models_in_c++.html">
            
                    
                    C++数据模型（Models in C++）
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.16.5.1" data-path="../qt_and_c++/a_simple_model.html">
            
                <a href="../qt_and_c++/a_simple_model.html">
            
                    
                    一个简单的模型（A simple model）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.16.5.2" data-path="../qt_and_c++/more_complex_data.html">
            
                <a href="../qt_and_c++/more_complex_data.html">
            
                    
                    更复杂的数据（More Complex Data）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.16.5.3" data-path="../qt_and_c++/dynamic_data.html">
            
                <a href="../qt_and_c++/dynamic_data.html">
            
                    
                    动态数据（Dynamic Data）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.16.5.4" data-path="../qt_and_c++/advanced_techniques.html">
            
                <a href="../qt_and_c++/advanced_techniques.html">
            
                    
                    进阶技巧（Advanced Techniques）
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.17" data-path="../extending_qml_with_c++/">
            
                <a href="../extending_qml_with_c++/">
            
                    
                    C++扩展QML（Extending QML with C++）
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.17.1" data-path="../extending_qml_with_c++/understanding_the_qml_run-time.html">
            
                <a href="../extending_qml_with_c++/understanding_the_qml_run-time.html">
            
                    
                    理解QML运行环境（Understanding the QML Run-time）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.17.2" data-path="../extending_qml_with_c++/plugin_content.html">
            
                <a href="../extending_qml_with_c++/plugin_content.html">
            
                    
                    插件内容（Plugin Content）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.17.3" data-path="../extending_qml_with_c++/creating_the_plugin.html">
            
                <a href="../extending_qml_with_c++/creating_the_plugin.html">
            
                    
                    创建插件（Creating the plugin）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.17.4" data-path="../extending_qml_with_c++/fileio_implementation.html">
            
                <a href="../extending_qml_with_c++/fileio_implementation.html">
            
                    
                    FileIO实现（FileIO Implementation）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.17.5" data-path="../extending_qml_with_c++/using_fileio.html">
            
                <a href="../extending_qml_with_c++/using_fileio.html">
            
                    
                    使用FileIO（Using FileIO）
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.17.5.1" data-path="../extending_qml_with_c++/the_application_window.html">
            
                <a href="../extending_qml_with_c++/the_application_window.html">
            
                    
                    应用程序窗口（The Application Window）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.17.5.2" data-path="../extending_qml_with_c++/using_actions.html">
            
                <a href="../extending_qml_with_c++/using_actions.html">
            
                    
                    使用动作（Using Actions）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.17.5.3" data-path="../extending_qml_with_c++/formatting_the_table.html">
            
                <a href="../extending_qml_with_c++/formatting_the_table.html">
            
                    
                    格式化表格（Formatting the Table）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.17.5.4" data-path="../extending_qml_with_c++/reading_data.html">
            
                <a href="../extending_qml_with_c++/reading_data.html">
            
                    
                    读取数据（Reading Data）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.17.5.5" data-path="../extending_qml_with_c++/writing_data.html">
            
                <a href="../extending_qml_with_c++/writing_data.html">
            
                    
                    写入数据（Writing Data）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.17.5.6" data-path="../extending_qml_with_c++/finishing_touch.html">
            
                <a href="../extending_qml_with_c++/finishing_touch.html">
            
                    
                    收尾工作（Finishing Touch）
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.17.6" data-path="../extending_qml_with_c++/summary.html">
            
                <a href="../extending_qml_with_c++/summary.html">
            
                    
                    总结（Summary）
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.18" data-path="../other/">
            
                <a href="../other/">
            
                    
                    其它（Other）
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.18.1" data-path="../other/assets.html">
            
                <a href="../other/assets.html">
            
                    
                    示例源码
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.18.2" data-path="../other/enginsh_to_chinses.html">
            
                <a href="../other/enginsh_to_chinses.html">
            
                    
                    术语英汉对照表
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.18.3" data-path="../other/book_format.html">
            
                <a href="../other/book_format.html">
            
                    
                    格式定义
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.18.4" data-path="../other/collaboration_correction.html">
            
                <a href="../other/collaboration_correction.html">
            
                    
                    协作校正
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >REST接口（REST API）</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="rest&#x63A5;&#x53E3;&#xFF08;rest-api&#xFF09;">REST&#x63A5;&#x53E3;&#xFF08;REST API&#xFF09;</h1>
<p>&#x4E3A;&#x4E86;&#x4F7F;&#x7528;web&#x670D;&#x52A1;&#xFF0C;&#x6211;&#x4EEC;&#x9996;&#x5148;&#x9700;&#x8981;&#x521B;&#x5EFA;&#x5B83;&#x3002;&#x6211;&#x4EEC;&#x4F7F;&#x7528;Flask&#xFF08;<a href="http://flask.pocoo.org&#xFF09;&#xFF0C;&#x4E00;&#x4E2A;&#x57FA;&#x4E8E;python&#x521B;&#x5EFA;&#x7B80;&#x5355;&#x7684;&#x989C;&#x8272;web&#x670D;&#x52A1;&#x7684;HTTP&#x670D;&#x52A1;&#x5668;&#x5E94;&#x7528;&#x3002;&#x4F60;&#x4E5F;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;&#x5176;&#x5B83;&#x7684;web&#x670D;&#x52A1;&#x5668;&#xFF0C;&#x53EA;&#x8981;&#x5B83;&#x63A5;&#x6536;&#x548C;&#x8FD4;&#x56DE;JSON&#x6570;&#x636E;&#x3002;&#x901A;&#x8FC7;web&#x670D;&#x52A1;&#x6765;&#x7BA1;&#x7406;&#x4E00;&#x7EC4;&#x5DF2;&#x7ECF;&#x547D;&#x540D;&#x7684;&#x989C;&#x8272;&#x3002;&#x5728;&#x8FD9;&#x4E2A;&#x4F8B;&#x5B50;&#x4E2D;&#xFF0C;&#x7BA1;&#x7406;&#x610F;&#x5473;&#x7740;CRUD&#xFF08;&#x521B;&#x5EFA;-&#x8BFB;&#x53D6;-&#x66F4;&#x65B0;-&#x5220;&#x9664;&#xFF09;&#x3002;" target="_blank">http://flask.pocoo.org&#xFF09;&#xFF0C;&#x4E00;&#x4E2A;&#x57FA;&#x4E8E;python&#x521B;&#x5EFA;&#x7B80;&#x5355;&#x7684;&#x989C;&#x8272;web&#x670D;&#x52A1;&#x7684;HTTP&#x670D;&#x52A1;&#x5668;&#x5E94;&#x7528;&#x3002;&#x4F60;&#x4E5F;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;&#x5176;&#x5B83;&#x7684;web&#x670D;&#x52A1;&#x5668;&#xFF0C;&#x53EA;&#x8981;&#x5B83;&#x63A5;&#x6536;&#x548C;&#x8FD4;&#x56DE;JSON&#x6570;&#x636E;&#x3002;&#x901A;&#x8FC7;web&#x670D;&#x52A1;&#x6765;&#x7BA1;&#x7406;&#x4E00;&#x7EC4;&#x5DF2;&#x7ECF;&#x547D;&#x540D;&#x7684;&#x989C;&#x8272;&#x3002;&#x5728;&#x8FD9;&#x4E2A;&#x4F8B;&#x5B50;&#x4E2D;&#xFF0C;&#x7BA1;&#x7406;&#x610F;&#x5473;&#x7740;CRUD&#xFF08;&#x521B;&#x5EFA;-&#x8BFB;&#x53D6;-&#x66F4;&#x65B0;-&#x5220;&#x9664;&#xFF09;&#x3002;</a></p>
<p>&#x5728;Flask&#x4E2D;&#x4E00;&#x4E2A;&#x7B80;&#x5355;&#x7684;web&#x670D;&#x52A1;&#x53EF;&#x4EE5;&#x5199;&#x5165;&#x4E00;&#x4E2A;&#x6587;&#x4EF6;&#x3002;&#x6211;&#x4EEC;&#x4F7F;&#x7528;&#x4E00;&#x4E2A;&#x7A7A;&#x7684;&#x670D;&#x52A1;&#x5668;.py&#x6587;&#x4EF6;&#x5F00;&#x59CB;&#xFF0C;&#x5728;&#x8FD9;&#x4E2A;&#x6587;&#x4EF6;&#x4E2D;&#x6211;&#x4EEC;&#x521B;&#x5EFA;&#x4E00;&#x4E9B;&#x89C4;&#x5219;&#x5E76;&#x4E14;&#x4ECE;&#x989D;&#x5916;&#x7684;JSON&#x6587;&#x4EF6;&#x4E2D;&#x52A0;&#x8F7D;&#x521D;&#x59CB;&#x989C;&#x8272;&#x3002;&#x4F60;&#x53EF;&#x4EE5;&#x67E5;&#x770B;Flask&#x6587;&#x6863;&#x83B7;&#x53D6;&#x66F4;&#x591A;&#x7684;&#x5E2E;&#x52A9;&#x3002;</p>
<pre><code>from flask import Flask, jsonify, request
import json

colors = json.load(file(&apos;colors.json&apos;, &apos;r&apos;))

app = Flask(__name__)

# ... service calls go here

if __name__ == &apos;__main__&apos;:
    app.run(debug = True)
</code></pre><p>&#x5F53;&#x4F60;&#x8FD0;&#x884C;&#x8FD9;&#x4E2A;&#x811A;&#x672C;&#x540E;&#xFF0C;&#x5B83;&#x4F1A;&#x5728;<a href="http://localhost:5000&#x3002;" target="_blank">http://localhost:5000&#x3002;</a></p>
<p>&#x6211;&#x4EEC;&#x5F00;&#x59CB;&#x6DFB;&#x52A0;&#x6211;&#x4EEC;&#x7684;CRUD&#xFF08;&#x521B;&#x5EFA;&#xFF0C;&#x8BFB;&#x53D6;&#xFF0C;&#x66F4;&#x65B0;&#xFF0C;&#x5220;&#x9664;&#xFF09;&#x5230;&#x6211;&#x4EEC;&#x7684;web&#x670D;&#x52A1;&#x3002;</p>
<h2 id="1151-&#x8BFB;&#x53D6;&#x8BF7;&#x6C42;&#xFF08;read-request&#xFF09;">11.5.1 &#x8BFB;&#x53D6;&#x8BF7;&#x6C42;&#xFF08;Read Request&#xFF09;</h2>
<p>&#x4ECE;web&#x670D;&#x52A1;&#x8BFB;&#x53D6;&#x6570;&#x636E;&#xFF0C;&#x6211;&#x4EEC;&#x63D0;&#x4F9B;GET&#x65B9;&#x6CD5;&#x6765;&#x8BFB;&#x53D6;&#x6240;&#x6709;&#x7684;&#x989C;&#x8272;&#x3002;</p>
<pre><code>@app.route(&apos;/colors&apos;, methods = [&apos;GET&apos;])
def get_colors():
    return jsonify( { &quot;colors&quot; :  colors })
</code></pre><p>&#x8FD9;&#x5C06;&#x4F1A;&#x8FD4;&#x56DE;&#x2018;/colors&#x2019;&#x4E0B;&#x7684;&#x989C;&#x8272;&#x3002;&#x6211;&#x4EEC;&#x4F7F;&#x7528;curl&#x6765;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;http&#x8BF7;&#x6C42;&#x6D4B;&#x8BD5;&#x3002;</p>
<pre><code>curl -i -GET http://localhost:5000/colors
</code></pre><p>&#x8FD9;&#x5C06;&#x4F1A;&#x8FD4;&#x56DE;&#x7ED9;&#x6211;&#x4EEC;JSON&#x6570;&#x636E;&#x7684;&#x989C;&#x8272;&#x94FE;&#x8868;&#x3002;</p>
<h2 id="1152-&#x8BFB;&#x53D6;&#x63A5;&#x53E3;&#xFF08;read-entry&#xFF09;">11.5.2 &#x8BFB;&#x53D6;&#x63A5;&#x53E3;&#xFF08;Read Entry&#xFF09;</h2>
<p>&#x4E3A;&#x4E86;&#x901A;&#x8FC7;&#x540D;&#x5B57;&#x8BFB;&#x53D6;&#x989C;&#x8272;&#xFF0C;&#x6211;&#x4EEC;&#x63D0;&#x4F9B;&#x66F4;&#x52A0;&#x8BE6;&#x7EC6;&#x7684;&#x540E;&#x7F00;&#xFF0C;&#x5B9A;&#x4F4D;&#x5728;&#x2018;/colors/&apos;&#x4E0B;&#x3002;&#x540D;&#x79F0;&#x662F;&#x540E;&#x7F00;&#x7684;&#x53C2;&#x6570;&#xFF0C;&#x7528;&#x6765;&#x8BC6;&#x522B;&#x4E00;&#x4E2A;&#x72EC;&#x7ACB;&#x7684;&#x989C;&#x8272;&#x3002;</p>
<pre><code>@app.route(&apos;/colors/&lt;name&gt;&apos;, methods = [&apos;GET&apos;])
def get_color(name):
    for color in colors:
        if color[&quot;name&quot;] == name:
            return jsonify( color )
</code></pre><p>&#x6211;&#x4EEC;&#x518D;&#x6B21;&#x4F7F;&#x7528;curl&#x6D4B;&#x8BD5;&#xFF0C;&#x4F8B;&#x5982;&#x83B7;&#x53D6;&#x4E00;&#x4E2A;&#x7EA2;&#x8272;&#x7684;&#x63A5;&#x53E3;&#x3002;</p>
<pre><code>curl -i -GET http://localhost:5000/colors/red
</code></pre><p>&#x8FD9;&#x5C06;&#x8FD4;&#x56DE;&#x4E00;&#x4E2A;JSON&#x6570;&#x636E;&#x7684;&#x989C;&#x8272;&#x3002;</p>
<h2 id="1153-&#x521B;&#x5EFA;&#x63A5;&#x53E3;&#xFF08;create-entry&#xFF09;">11.5.3 &#x521B;&#x5EFA;&#x63A5;&#x53E3;&#xFF08;Create Entry&#xFF09;</h2>
<p>&#x76EE;&#x524D;&#x6211;&#x4EEC;&#x4EC5;&#x4EC5;&#x4F7F;&#x7528;&#x4E86;HTTP GET&#x65B9;&#x6CD5;&#x3002;&#x4E3A;&#x4E86;&#x5728;&#x670D;&#x52A1;&#x5668;&#x7AEF;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x63A5;&#x53E3;&#xFF0C;&#x6211;&#x4EEC;&#x4F7F;&#x7528;POST&#x65B9;&#x6CD5;&#xFF0C;&#x5E76;&#x4E14;&#x5C06;&#x65B0;&#x7684;&#x989C;&#x8272;&#x4FE1;&#x606F;&#x53D1;&#x4F7F;&#x7528;POST&#x6570;&#x636E;&#x53D1;&#x9001;&#x3002;&#x540E;&#x7F00;&#x4E0E;&#x83B7;&#x53D6;&#x6240;&#x6709;&#x989C;&#x8272;&#x76F8;&#x540C;&#xFF0C;&#x4F46;&#x662F;&#x6211;&#x4EEC;&#x9700;&#x8981;&#x4F7F;&#x7528;&#x4E00;&#x4E2A;POST&#x8BF7;&#x6C42;&#x3002;</p>
<pre><code>@app.route(&apos;/colors&apos;, methods= [&apos;POST&apos;])
def create_color():
    color = {
        &apos;name&apos;: request.json[&apos;name&apos;],
        &apos;value&apos;: request.json[&apos;value&apos;]
    }
    colors.append(color)
    return jsonify( color ), 201
</code></pre><p>curl&#x975E;&#x5E38;&#x7075;&#x6D3B;&#xFF0C;&#x5141;&#x8BB8;&#x6211;&#x4EEC;&#x4F7F;&#x7528;JSON&#x6570;&#x636E;&#x4F5C;&#x4E3A;&#x65B0;&#x7684;&#x63A5;&#x53E3;&#x5305;&#x542B;&#x5728;POST&#x8BF7;&#x6C42;&#x4E2D;&#x3002;</p>
<pre><code>curl -i -H &quot;Content-Type: application/json&quot; -X POST -d &apos;{&quot;name&quot;:&quot;gray1&quot;,&quot;value&quot;:&quot;#333&quot;}&apos; http://localhost:5000/colors
</code></pre><h2 id="1154-&#x66F4;&#x65B0;&#x63A5;&#x53E3;&#xFF08;update-entry&#xFF09;">11.5.4 &#x66F4;&#x65B0;&#x63A5;&#x53E3;&#xFF08;Update Entry&#xFF09;</h2>
<p>&#x6211;&#x4EEC;&#x4F7F;&#x7528;PUT HTTP&#x65B9;&#x6CD5;&#x6765;&#x6DFB;&#x52A0;&#x65B0;&#x7684;update&#x63A5;&#x53E3;&#x3002;&#x540E;&#x7F00;&#x4E0E;&#x53D6;&#x5F97;&#x4E00;&#x4E2A;&#x989C;&#x8272;&#x63A5;&#x53E3;&#x76F8;&#x540C;&#x3002;&#x5F53;&#x989C;&#x8272;&#x66F4;&#x65B0;&#x540E;&#xFF0C;&#x6211;&#x4EEC;&#x83B7;&#x53D6;&#x66F4;&#x65B0;&#x540E;JSON&#x6570;&#x636E;&#x7684;&#x989C;&#x8272;&#x3002;</p>
<pre><code>@app.route(&apos;/colors/&lt;name&gt;&apos;, methods= [&apos;PUT&apos;])
def update_color(name):
    for color in colors:
        if color[&quot;name&quot;] == name:
            color[&apos;value&apos;] = request.json.get(&apos;value&apos;, color[&apos;value&apos;])
            return jsonify( color )
</code></pre><p>&#x5728;curl&#x8BF7;&#x6C42;&#x4E2D;&#xFF0C;&#x6211;&#x4EEC;&#x7528;JSON&#x6570;&#x636E;&#x6765;&#x5B9A;&#x4E49;&#x66F4;&#x65B0;&#x503C;&#xFF0C;&#x540E;&#x7F00;&#x540D;&#x7528;&#x6765;&#x8BC6;&#x522B;&#x54EA;&#x4E2A;&#x989C;&#x8272;&#x9700;&#x8981;&#x66F4;&#x65B0;&#x3002;</p>
<pre><code>curl -i -H &quot;Content-Type: application/json&quot; -X PUT -d &apos;{&quot;value&quot;:&quot;#666&quot;}&apos; http://localhost:5000/colors/red
</code></pre><h2 id="1155-&#x5220;&#x9664;&#x63A5;&#x53E3;&#xFF08;delete-entry&#xFF09;">11.5.5 &#x5220;&#x9664;&#x63A5;&#x53E3;&#xFF08;Delete Entry&#xFF09;</h2>
<p>&#x4F7F;&#x7528;DELETE HTTP&#x6765;&#x5B8C;&#x6210;&#x5220;&#x9664;&#x63A5;&#x53E3;&#x3002;&#x4F7F;&#x7528;&#x4E0E;&#x989C;&#x8272;&#x76F8;&#x540C;&#x7684;&#x540E;&#x7F00;&#xFF0C;&#x4F46;&#x662F;&#x4F7F;&#x7528;DELETE HTTP&#x65B9;&#x6CD5;&#x3002;</p>
<pre><code>@app.route(&apos;/colors/&lt;name&gt;&apos;, methods=[&apos;DELETE&apos;])
def delete_color(name):
    success = False
    for color in colors:
        if color[&quot;name&quot;] == name:
            colors.remove(color)
            success = True
    return jsonify( { &apos;result&apos; : success } )
</code></pre><p>&#x8FD9;&#x4E2A;&#x8BF7;&#x6C42;&#x770B;&#x8D77;&#x6765;&#x4E0E;GET&#x8BF7;&#x6C42;&#x4E00;&#x4E2A;&#x989C;&#x8272;&#x7C7B;&#x4F3C;&#x3002;</p>
<pre><code>curl -i -X DELETE http://localhost:5000/colors/red
</code></pre><p>&#x73B0;&#x5728;&#x6211;&#x4EEC;&#x80FD;&#x591F;&#x8BFB;&#x53D6;&#x6240;&#x6709;&#x989C;&#x8272;&#xFF0C;&#x8BFB;&#x53D6;&#x6307;&#x5B9A;&#x989C;&#x8272;&#xFF0C;&#x521B;&#x5EFA;&#x65B0;&#x7684;&#x989C;&#x8272;&#xFF0C;&#x66F4;&#x65B0;&#x989C;&#x8272;&#x548C;&#x5220;&#x9664;&#x989C;&#x8272;&#x3002;&#x6211;&#x4EEC;&#x77E5;&#x9053;&#x4F7F;&#x7528;HTTP&#x540E;&#x7F00;&#x6765;&#x8BBF;&#x95EE;&#x6211;&#x4EEC;&#x7684;&#x63A5;&#x53E3;&#x3002;</p>
<table>
<thead>
<tr>
<th>&#x52A8;&#x4F5C;</th>
<th>HTTP&#x534F;&#x8BAE;</th>
<th>&#x540E;&#x7F00;</th>
</tr>
</thead>
<tbody>
<tr>
<td>&#x8BFB;&#x53D6;&#x6240;&#x6709;</td>
<td>GET</td>
<td><a href="http://localhost:5000/colors" target="_blank">http://localhost:5000/colors</a></td>
</tr>
<tr>
<td>&#x521B;&#x5EFA;&#x63A5;&#x53E3;</td>
<td>POST</td>
<td><a href="http://localhost:5000/colors" target="_blank">http://localhost:5000/colors</a></td>
</tr>
<tr>
<td>&#x8BFB;&#x53D6;&#x63A5;&#x53E3;</td>
<td>GET</td>
<td><a href="http://localhost:5000/colors/name" target="_blank">http://localhost:5000/colors/name</a></td>
</tr>
<tr>
<td>&#x66F4;&#x65B0;&#x63A5;&#x53E3;</td>
<td>PUT</td>
<td><a href="http://localhost:5000/colors/name" target="_blank">http://localhost:5000/colors/name</a></td>
</tr>
<tr>
<td>&#x5220;&#x9664;&#x63A5;&#x53E3;</td>
<td>DELETE</td>
<td><a href="http://localhost:500/colors/name" target="_blank">http://localhost:500/colors/name</a></td>
</tr>
</tbody>
</table>
<p>REST&#x670D;&#x52A1;&#x5DF2;&#x7ECF;&#x5B8C;&#x6210;&#xFF0C;&#x6211;&#x4EEC;&#x73B0;&#x5728;&#x53EA;&#x9700;&#x8981;&#x5173;&#x6CE8;QML&#x548C;&#x5BA2;&#x6237;&#x7AEF;&#x3002;&#x4E3A;&#x4E86;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x7B80;&#x5355;&#x597D;&#x7528;&#x7684;&#x63A5;&#x53E3;&#xFF0C;&#x6211;&#x4EEC;&#x9700;&#x8981;&#x6620;&#x5C04;&#x6BCF;&#x4E2A;&#x52A8;&#x4F5C;&#x4E3A;&#x4E00;&#x4E2A;&#x72EC;&#x7ACB;&#x7684;HTTP&#x8BF7;&#x6C42;&#xFF0C;&#x5E76;&#x4E14;&#x7ED9;&#x6211;&#x4EEC;&#x7684;&#x7528;&#x6237;&#x63D0;&#x4F9B;&#x4E00;&#x4E2A;&#x7B80;&#x5355;&#x7684;&#x63A5;&#x53E3;&#x3002;</p>
<h2 id="1156-rest&#x5BA2;&#x6237;&#x7AEF;&#xFF08;rest-client&#xFF09;">11.5.6 REST&#x5BA2;&#x6237;&#x7AEF;&#xFF08;REST Client&#xFF09;</h2>
<p>&#x4E3A;&#x4E86;&#x5C55;&#x793A;REST&#x5BA2;&#x6237;&#x7AEF;&#xFF0C;&#x6211;&#x4EEC;&#x5199;&#x4E86;&#x4E00;&#x4E2A;&#x5C0F;&#x7684;&#x989C;&#x8272;&#x8868;&#x683C;&#x3002;&#x8FD9;&#x4E2A;&#x989C;&#x8272;&#x8868;&#x683C;&#x663E;&#x793A;&#x4E86;&#x901A;&#x8FC7;HTTP&#x8BF7;&#x6C42;&#x4ECE;web&#x670D;&#x52A1;&#x53D6;&#x5F97;&#x7684;&#x989C;&#x8272;&#x3002;&#x6211;&#x4EEC;&#x7684;&#x7528;&#x6237;&#x754C;&#x9762;&#x63D0;&#x4F9B;&#x4EE5;&#x4E0B;&#x547D;&#x4EE4;&#xFF1A;</p>
<ul>
<li><p>&#x83B7;&#x53D6;&#x989C;&#x8272;&#x94FE;&#x8868;</p>
</li>
<li><p>&#x521B;&#x5EFA;&#x989C;&#x8272;</p>
</li>
<li><p>&#x8BFB;&#x53D6;&#x6700;&#x540E;&#x7684;&#x989C;&#x8272;</p>
</li>
<li><p>&#x66F4;&#x65B0;&#x6700;&#x540E;&#x7684;&#x989C;&#x8272;</p>
</li>
<li><p>&#x5220;&#x9664;&#x6700;&#x540E;&#x7684;&#x989C;&#x8272;</p>
</li>
</ul>
<p>&#x6211;&#x4EEC;&#x5C06;&#x6211;&#x4EEC;&#x7684;&#x63A5;&#x53E3;&#x5305;&#x88C5;&#x5728;&#x4E00;&#x4E2A;JS&#x6587;&#x4EF6;&#x4E2D;&#xFF0C;&#x53EB;&#x505A;colorservice.js&#xFF0C;&#x5E76;&#x5C06;&#x5B83;&#x5BFC;&#x5165;&#x5230;&#x6211;&#x4EEC;&#x7684;UI&#x4E2D;&#x4F5C;&#x4E3A;&#x670D;&#x52A1;&#xFF08;Service&#xFF09;&#x3002;&#x5728;&#x670D;&#x52A1;&#x6A21;&#x5757;&#x4E2D;&#xFF0C;&#x6211;&#x4EEC;&#x521B;&#x5EFA;&#x4E86;&#x5E2E;&#x52A9;&#x51FD;&#x6570;&#x6765;&#x4E3A;&#x6211;&#x4EEC;&#x6784;&#x9020;HTTP&#x8BF7;&#x6C42;&#xFF1A;</p>
<pre><code>// colorservice.js
function request(verb, endpoint, obj, cb) {
    print(&apos;request: &apos; + verb + &apos; &apos; + BASE + (endpoint?&apos;/&apos; + endpoint:&apos;&apos;))
    var xhr = new XMLHttpRequest();
    xhr.onreadystatechange = function() {
        print(&apos;xhr: on ready state change: &apos; + xhr.readyState)
        if(xhr.readyState === XMLHttpRequest.DONE) {
            if(cb) {
                var res = JSON.parse(xhr.responseText.toString())
                cb(res);
            }
        }
    }
    xhr.open(verb, BASE + (endpoint?&apos;/&apos; + endpoint:&apos;&apos;));
    xhr.setRequestHeader(&apos;Content-Type&apos;, &apos;application/json&apos;);
    xhr.setRequestHeader(&apos;Accept&apos;, &apos;application/json&apos;);
    var data = obj?JSON.stringify(obj):&apos;&apos;
    xhr.send(data)
}
</code></pre><p>&#x5305;&#x542B;&#x56DB;&#x4E2A;&#x53C2;&#x6570;&#x3002;verb&#xFF0C;&#x5B9A;&#x4E49;&#x4E86;&#x4F7F;&#x7528;HTTP&#x7684;&#x52A8;&#x4F5C;&#xFF08;GET&#xFF0C;POST&#xFF0C;PUT&#xFF0C;DELETE&#xFF09;&#x3002;&#x7B2C;&#x4E8C;&#x4E2A;&#x53C2;&#x6570;&#x662F;&#x4F5C;&#x4E3A;&#x57FA;&#x7840;&#x5730;&#x5740;&#x7684;&#x540E;&#x7F00;&#xFF08;&#x4F8B;&#x5982;&#x2019;<a href="http://localhost:5000/colors" target="_blank">http://localhost:5000/colors</a>&apos;&#xFF09;&#x3002;&#x7B2C;&#x4E09;&#x4E2A;&#x53C2;&#x6570;&#x662F;&#x53EF;&#x9009;&#x5BF9;&#x8C61;&#xFF0C;&#x4F5C;&#x4E3A;JSON&#x6570;&#x636E;&#x53D1;&#x9001;&#x7ED9;&#x670D;&#x52A1;&#x7684;&#x6570;&#x636E;&#x3002;&#x6700;&#x540E;&#x4E00;&#x4E2A;&#x9009;&#x9879;&#x662F;&#x5B9A;&#x4E49;&#x5F53;&#x54CD;&#x5E94;&#x8FD4;&#x56DE;&#x65F6;&#x7684;&#x56DE;&#x8C03;&#x3002;&#x56DE;&#x8C03;&#x63A5;&#x6536;&#x4E00;&#x4E2A;&#x54CD;&#x5E94;&#x6570;&#x636E;&#x7684;&#x54CD;&#x5E94;&#x5BF9;&#x8C61;&#x3002;</p>
<p>&#x5728;&#x6211;&#x4EEC;&#x53D1;&#x9001;&#x8BF7;&#x6C42;&#x524D;&#xFF0C;&#x6211;&#x4EEC;&#x9700;&#x8981;&#x660E;&#x786E;&#x6211;&#x4EEC;&#x53D1;&#x9001;&#x548C;&#x63A5;&#x6536;&#x7684;JSON&#x6570;&#x636E;&#x4FEE;&#x6539;&#x7684;&#x8BF7;&#x6C42;&#x5934;&#x3002;</p>
<pre><code>// colorservice.js
function get_colors(cb) {
    // GET http://localhost:5000/colors
    request(&apos;GET&apos;, null, null, cb)
}

function create_color(entry, cb) {
    // POST http://localhost:5000/colors
    request(&apos;POST&apos;, null, entry, cb)
}

function get_color(name, cb) {
    // GET http://localhost:5000/colors/&lt;name&gt;
    request(&apos;GET&apos;, name, null, cb)
}

function update_color(name, entry, cb) {
    // PUT http://localhost:5000/colors/&lt;name&gt;
    request(&apos;PUT&apos;, name, entry, cb)
}

function delete_color(name, cb) {
    // DELETE http://localhost:5000/colors/&lt;name&gt;
    request(&apos;DELETE&apos;, name, null, cb)
}
</code></pre><p>&#x8FD9;&#x4E9B;&#x4EE3;&#x7801;&#x5728;&#x670D;&#x52A1;&#x5B9E;&#x73B0;&#x4E2D;&#x3002;&#x5728;UI&#x4E2D;&#x6211;&#x4EEC;&#x4F7F;&#x7528;&#x670D;&#x52A1;&#x6765;&#x5B9E;&#x73B0;&#x6211;&#x4EEC;&#x7684;&#x547D;&#x4EE4;&#x3002;&#x6211;&#x4EEC;&#x6709;&#x4E00;&#x4E2A;&#x5B58;&#x50A8;id&#x7684;ListModel&#x548C;&#x5B58;&#x50A8;&#x6570;&#x636E;&#x7684;gridModel&#x4E3A;GridView&#x63D0;&#x4F9B;&#x6570;&#x636E;&#x3002;&#x547D;&#x4EE4;&#x4F7F;&#x7528;Button&#x5143;&#x7D20;&#x6765;&#x53D1;&#x9001;&#x3002;</p>
<p>&#x8BFB;&#x53D6;&#x670D;&#x52A1;&#x5668;&#x989C;&#x8272;&#x94FE;&#x8868;&#x3002;</p>
<pre><code>// rest.qml
import &quot;colorservice.js&quot; as Service
...
// read colors command
Button {
    text: &apos;Read Colors&apos;;
    onClicked: {
        Service.get_colors( function(resp) {
            print(&apos;handle get colors resp: &apos; + JSON.stringify(resp));
            gridModel.clear();
            var entries = resp.data;
            for(var i=0; i&lt;entries.length; i++) {
                gridModel.append(entries[i]);
            }
        });
    }
}
</code></pre><p>&#x5728;&#x670D;&#x52A1;&#x5668;&#x4E0A;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x65B0;&#x7684;&#x989C;&#x8272;&#x3002;</p>
<pre><code>// rest.qml
import &quot;colorservice.js&quot; as Service
...
// create new color command
Button {
    text: &apos;Create New&apos;;
    onClicked: {
        var index = gridModel.count-1
        var entry = {
            name: &apos;color-&apos; + index,
            value: Qt.hsla(Math.random(), 0.5, 0.5, 1.0).toString()
        }
        Service.create_color(entry, function(resp) {
            print(&apos;handle create color resp: &apos; + JSON.stringify(resp))
            gridModel.append(resp)
        });
    }
}
</code></pre><p>&#x57FA;&#x4E8E;&#x540D;&#x79F0;&#x8BFB;&#x53D6;&#x4E00;&#x4E2A;&#x989C;&#x8272;&#x3002;</p>
<pre><code>// rest.qml
import &quot;colorservice.js&quot; as Service
...
// read last color command
Button {
    text: &apos;Read Last Color&apos;;
    onClicked: {
        var index = gridModel.count-1
        var name = gridModel.get(index).name
        Service.get_color(name, function(resp) {
            print(&apos;handle get color resp:&apos; + JSON.stringify(resp))
            message.text = resp.value
        });
    }
}
</code></pre><p>&#x57FA;&#x4E8E;&#x989C;&#x8272;&#x540D;&#x79F0;&#x66F4;&#x65B0;&#x670D;&#x52A1;&#x5668;&#x4E0A;&#x7684;&#x4E00;&#x4E2A;&#x989C;&#x8272;&#x3002;</p>
<pre><code>// rest.qml
import &quot;colorservice.js&quot; as Service
...
// update color command
Button {
    text: &apos;Update Last Color&apos;
    onClicked: {
        var index = gridModel.count-1
        var name = gridModel.get(index).name
        var entry = {
            value: Qt.hsla(Math.random(), 0.5, 0.5, 1.0).toString()
        }
        Service.update_color(name, entry, function(resp) {
            print(&apos;handle update color resp: &apos; + JSON.stringify(resp))
            var index = gridModel.count-1
            gridModel.setProperty(index, &apos;value&apos;, resp.value)
        });
    }
}
</code></pre><p>&#x57FA;&#x4E8E;&#x989C;&#x8272;&#x540D;&#x79F0;&#x5220;&#x9664;&#x4E00;&#x4E2A;&#x989C;&#x8272;&#x3002;</p>
<pre><code>// rest.qml
import &quot;colorservice.js&quot; as Service
...
// delete color command
Button {
    text: &apos;Delete Last Color&apos;
    onClicked: {
        var index = gridModel.count-1
        var name = gridModel.get(index).name
        Service.delete_color(name)
        gridModel.remove(index, 1)
    }
}
</code></pre><p>&#x5728;CRUD&#xFF08;&#x521B;&#x5EFA;&#xFF0C;&#x8BFB;&#x53D6;&#xFF0C;&#x66F4;&#x65B0;&#xFF0C;&#x5220;&#x9664;&#xFF09;&#x64CD;&#x4F5C;&#x4F7F;&#x7528;REST&#x63A5;&#x53E3;&#x3002;&#x4E5F;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;&#x5176;&#x5B83;&#x7684;&#x65B9;&#x6CD5;&#x6765;&#x521B;&#x5EFA;web&#x670D;&#x52A1;&#x63A5;&#x53E3;&#x3002;&#x53EF;&#x4EE5;&#x57FA;&#x4E8E;&#x6A21;&#x5757;&#xFF0C;&#x6BCF;&#x4E2A;&#x6A21;&#x5757;&#x90FD;&#x6709;&#x81EA;&#x5DF1;&#x7684;&#x540E;&#x7F00;&#x3002;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;JSON RPC&#xFF08;<a href="http://www.jsonrpc.org/" target="_blank">http://www.jsonrpc.org/</a>&#xFF09;&#x6765;&#x5B9A;&#x4E49;&#x63A5;&#x53E3;&#x3002;&#x5F53;&#x7136;&#x57FA;&#x4E8E;XML&#x7684;&#x63A5;&#x53E3;&#x4E5F;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;&#xFF0C;&#x4F46;&#x662F;JSON&#x5728;&#x4F5C;&#x4E3A;JavaScript&#x90E8;&#x5206;&#x89E3;&#x6790;&#x8FDB;QML/JS&#x4E2D;&#x66F4;&#x6709;&#x4F18;&#x52BF;&#x3002;</p>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="local_files.html" class="navigation navigation-prev " aria-label="Previous page: 本地文件（Local files）">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="authentication_using_oauth.html" class="navigation navigation-next " aria-label="Next page: 使用开放授权登陆验证（Authentication using OAuth）">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"REST接口（REST API）","level":"1.12.5","depth":2,"next":{"title":"使用开放授权登陆验证（Authentication using OAuth）","level":"1.12.6","depth":2,"path":"networking/authentication_using_oauth.md","ref":"networking/authentication_using_oauth.md","articles":[]},"previous":{"title":"本地文件（Local files）","level":"1.12.4","depth":2,"path":"networking/local_files.md","ref":"networking/local_files.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":[],"pluginsConfig":{"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"networking/restrest_api.md","mtime":"2021-05-30T14:00:08.981Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2021-05-30T14:16:45.097Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

